package com.chenjt.netty.six_gPRC.simple;

import com.chenjt.netty.six_gPRC.generateCode.MyRequest;
import com.chenjt.netty.six_gPRC.generateCode.MyResponse;
import com.chenjt.netty.six_gPRC.generateCode.StudentServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

/**
 * gRPC客户端
 *
 * 参考D:\programmer\studyWorkspace\netty\doc\grpc-java\examples\src\main\java\io\grpc\examples\helloworld\HelloWorldClient.java
 * @author chenjt
 * @date 2024/8/16 10:36
 */
public class GrpcClient {

    public static void main(String[] args) {
        ManagedChannel managedChannel = ManagedChannelBuilder.forAddress("localhost", 8899)
//                .usePlaintext(true)
                .usePlaintext()
                .build();

        StudentServiceGrpc.StudentServiceBlockingStub blockingStub
                = StudentServiceGrpc.newBlockingStub(managedChannel);
        MyResponse myResponse = blockingStub.getRealNameByUsername(MyRequest.newBuilder()
                .setUsername("zhangsan").build());

        System.out.println(myResponse.getRealname());

        // 当重复调用时，是会复用该链接的
        myResponse = blockingStub.getRealNameByUsername(MyRequest.newBuilder()
                .setUsername("zhangsan").build());

        System.out.println(myResponse.getRealname());


    }



}
